1. Technical Field
The present invention relates to an improved data processing system and in particular to a method and apparatus for executing a method. Still more particularly, the present invention relates to a method and apparatus for speeding up execution of a method.
2. Description of Related Art
Java is an object oriented programming language and environment focusing on defining data as objects and the methods that may be applied to those objects. xe2x80x9cJavaxe2x80x9d is a trademark of Sun Microsystems, Inc. Java supports only a single inheritance, meaning that each class can inherit from only one other class at any given time. Java also allows for the creation of totally abstract classes known as interfaces, which allow the defining of methods that may be shared with several classes without regard for how other classes are handling the methods. Java provides a mechanism to distribute software to different computing platforms.
Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating system architectures. The Java Virtual Machine (JVM) is a virtual computer component that resides only in memory. The JVM allows Java programs to be executed on different platforms as opposed to only the one platform for which the code was compiled. Java programs are compiled for the JVM. In this manner, Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating systems architectures. To enable a Java application to execute on different types of data processing systems, a compiler typically generates an architecture-neutral file format. The compiled code is executable on many processors, given the presence of the Java runtime system. The Java compiler generates bytecode instructions that are non-specific to particular computer architectures. A bytecode is a machine independent code generated by the Java compiler and executed by a Java interpreter. A Java interpreter is a module in the JVM that alternatively decodes and executes a bytecode or bytecodes. These bytecode instructions are designed to be easy to interpret on any machine and easily translated on the fly into native machine code.
A development environment, such as the Java Development Kit (JDK) available from Sun Microsystems, Inc., may be used to build Java bytecode from Java language source code and libraries. This Java bytecode may be stored as a Java application or applet on a Web Server, where it can be downloaded over a network to a user""s machine and executed on a local JVM.
When extra speed in executing a Java program is needed, a Just In Time (JIT) compiler may be used to translate bytecodes for a method or class into native machine instructions before executing them. Typically, this compilation only occurs once per method. Some JIT compilers may compile entire classes, rather than one method at a time.
Bytecodes may be optimized for execution in a JVM. Presently, these optimizations occur during the runtime execution of bytecodes for a method. A number of problems exist with optimizing bytecodes during execution of the method. One problem associated with this type of technique is that a slight performance penalty is incurred during the execution of the method to perform the modification to the bytecode. This effect may be spread out over several invocations of the method since the bytecodes will only be modified as they are executed and different invocations will result in different code paths through the method being exercised. Thus, the execution speed of the method may vary depending upon whether or not the encountered bytecodes are being executed for the first time. Also, because each bytecode is optimized as it is encountered the setup and function call overhead must be incurred for each such optimization rather than a single time for multiple optimizations.
Some potential optimizations will require that a xe2x80x9ccode lockxe2x80x9d be obtained on the method to ensure that no other thread is executing in the method. This requirement can be very expensive with respect to the overall performance of the JVM and thus may prevent these potential bytecode optimizations from being used. Finally, additional bytecodes are necessary to support optimizing to macro bytecodes. The interpreter has logic for the original bytecode to determine if a macro bytecode optimization is possible. If optimization to a macro bytecode is not possible, then the original bytecode must be converted to an alternate form of the original bytecode. The interpreter logic for the alternate form of the original bytecode performs the same function as the original bytecode but does not perform the test for possible macro bytecode optimization to avoid this check on future executions of this bytecode. This situation requires the use of additional bytecodes from the very limited pool of free bytecode values.
Therefore, it would be advantageous to have an improved method and apparatus for optimizing the execution of bytecodes without incurring the penalties of existing techniques for optimizing the execution of bytecodes.
The present invention provides a method and apparatus for optimizing performance of a method. A method is loaded and verified in a virtual machine. Prior to first execution of the method, elements of the method are analyzed for optimization according to a policy. Responsive to identifying elements that can be optimized according to the policy, the elements are optimized following the policy and the method is then made available for execution. All methods undergo these optimizations prior to execution and the interpreter is modified to process the new encodings of the bytecode streams.